<%--
  Created by IntelliJ IDEA.
  User: zengyao
  Date: 2018/6/29
  Time: 17:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>新房管理</title>
    <link rel="stylesheet" href="${allServerPath}static/layui/layui/css/layui.css">
    <style>
        .query-condition {
            margin-top: 15px;
        }
    </style>
</head>
<body style="background-color: #f0f2f5;">
<div style="padding: 15px;margin: 15px;background-color: #fff;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>新房管理</legend>
    </fieldset>
    <form id="queryForm" class="layui-form" action="">
        <div class="layui-form-item query-condition">

            <div class="layui-inline">
                <label class="layui-form-label">楼盘名</label>

                <div class="layui-input-inline">
                    <input name="houseName" class="layui-input" type="text" placeholder="请输入楼盘名" autocomplete="off">
                </div>
            </div>
        </div>
    </form>
    <div class="layui-row" style="padding: 9px 15px;margin:15px 0 10px 0;">
        <button name="btn-add" class="layui-btn layui-btn-normal">添加</button>
        <button name="reQuery" class="layui-btn layui-btn-normal">查询搜索</button>
    </div>
    <table id="userInfo" lay-filter="test" lay-data="{height: 'full-200'}"></table>
</div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="manageImg">图片管理</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="manageComment">评分管理</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="manageLayout">户型管理</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="manageInfo">动态管理</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="manageTag">标签管理</a>
    <%--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="manageSecondhouseprice">二手房价格管理</a>--%>
    <a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
</script>


<script src="${allServerPath}static/layui/layui/layui.js"></script>
<script>
    layui.config({
        base: '${allServerPath}static/layui/build/js/'
    }).use(['table', 'jquery', 'navbar'], function () {
        var table = layui.table,
            $ = layui.jquery;

        table.render({
            elem: '#userInfo'
//            , height: 315
            , url: '${allServerPath}web/house/list.htmls?t=' + Date.parse(new Date()) //数据接口
            , page: true //开启分页
            , cols: [[ //表头
                {field: 'id', title: 'ID', width: 80, fixed: 'left'}
                , {field: 'houseName', title: '楼盘名称', align: 'center', width: 200}
                , {field: 'price', title: '均价', align: 'center', width: 100}
                , {field: 'area', title: '区域', align: 'center', width: 160}
                , {field: 'houseAddr', title: '地址', align: 'center', width: 280}
                , {field: 'contactPhone', title: '联系电话', align: 'center', width: 120}
                , {field: 'createDatetime', title: '添加时间', align: 'center', width: 180}
                , {fixed: 'right', width: 500, title: '操作', align: 'center', toolbar: '#barDemo'}
            ]],
            id: 'userContent',
            method: 'get',
            page: true,
            request: {
                pageName: 'pageIndex', //页码的参数名称，默认：page
                limitName: 'pageSize'
            }, //如果无需自定义请求参数，可不加该参数
            response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                , statusCode: 200 //成功的状态码，默认：0
                , msgName: 'message' //状态信息的字段名称，默认：msg
                , countName: 'total' //数据总数的字段名称，默认：count
                , dataName: 'data' //数据列表的字段名称，默认：data
            },
            done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                console.log(res);
                //得到当前页码
                console.log(curr);
                //得到数据总量
                console.log(count);
            },
            text: {
                none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            }

        });
        table.on('tool(test)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'edit') {
                layer.open({
                    type: 2,
                    title: '新房信息',
                    maxmin: true,
                    shadeClose: true, //点击遮罩关闭层
                    area: ['725px', '411px'],
                    content: '${allServerPath}web/house/edit/' + data.id + '.htmls'
                });
            } else if (layEvent === 'del') {
                layer.confirm('真的删除么', function (index) {
                    $.ajax({
                        url: '${allServerPath}web/house/delete/' + data.id + ".htmls",
                        method: 'get',
                        dataType: 'json',
                        success: function (result) {
                            if (result.success) {
                                obj.del(); //删除对应行（tr）的DOM结构
                                layer.close(index);//向服务端发送删除指令
                            }
                        },
                        error: function () {
                            layer.msg('删除失败,请稍后重试.');
                        }
                    });
                });
            } else if (layEvent === 'manageImg') {
                parent.window.tab.tabAdd({
                    'id': 'img' + data.id,
                    'title': '图片管理',
                    'icon': '',
                    'url': '${allServerPath}web/house/manageImg/' + data.id + '.htmls?houseType=1'
                });
            } else if (layEvent === 'manageComment') {
                parent.window.tab.tabAdd({
                    'id': 'comment' + data.id,
                    'title': '评分管理',
                    'icon': '',
                    'url': '${allServerPath}web/comment/toManageComment/' + data.id + '.htmls'
                });
            } else if (layEvent === 'manageLayout') {
                parent.window.tab.tabAdd({
                    'id': 'layout' + data.id,
                    'title': '户型管理',
                    'icon': '',
                    'url': '${allServerPath}web/house/manageLayout/' + data.id + '.htmls'
                });
            } else if (layEvent === 'manageInfo') {
                parent.window.tab.tabAdd({
                    'id': 'info' + data.id,
                    'title': '动态管理',
                    'icon': '',
                    'url': '${allServerPath}web/house/manageInfo/' + data.id + '.htmls'
                });
            } else if (layEvent === 'manageTag') {
                parent.window.tab.tabAdd({
                    'id': 'tag' + data.id,
                    'title': '标签管理',
                    'icon': '',
                    'url': '${allServerPath}web/house/manageTag/' + data.id + '.htmls'
                });
            }
        });

        $("button[name='btn-add']").click(function () {
            layer.open({
                type: 2,
                title: '新房信息',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['725px', '411px'],
                content: '${allServerPath}web/house/toAdd.htmls',
                end: function () {
                    table.reload('userContent', {});
                }
            });
        });

        $("button[name='reQuery']").click(function () {
            var houseName = $('input[name="houseName"]').val();
            table.reload('userContent', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    "name": houseName
                }
            });

        });
    });
</script>
</body>
</html>
